package com.jintoufs.dao.user.impl;

import com.jintoufs.dao.MyBatisSupport;
import com.jintoufs.dao.QueryFilters;
import com.jintoufs.dao.user.UserDAO;
import com.jintoufs.domain.user.User;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户管理dao层接口实现
 *
 * @author tcq
 */
@Repository
public class UserDAOImpl extends MyBatisSupport<UserDAO, User> implements UserDAO {
    private static Map<String, Object> fildMap = new HashMap<String, Object>() {
        {
            put("id", "u.id");
            put("userName", "u.user_name");
            put("realName", "u.real_name");
            put("password", "u.password");
            put("roleId", "u.role_id");
            put("roleName", "r.role_name");
            put("mobilePhone", "u.mobile_phone");
            put("sex", "u.sex");
            put("status", "u.status");
            put("type", "u.type");
            put("empNo", "u.emp_no");
            put("orgName", "o.org_name");
        }
    };

    @Override
    public List<Map> getByFilter(QueryFilters filters) {
        // 查询字段过滤，不允许不合法字段进入SQL
        filters.format(fildMap);
        return getMapper().getByFilter(filters);
    }

    @Override
    public Integer update(User user) {
        return getMapper().update(user);
    }

    @Override
    public Integer insert(User user) {
        return getMapper().insert(user);
    }

    @Override
    public void delete(Integer id) {
        getMapper().delete(id);
    }

    @Override
    public List<User> queryByParams(Map<String, Object> params) {
        return getMapper().queryByParams(params);
    }

    @Override
    public Map<String, Object> queryUserById(Integer id) {
        return getMapper().queryUserById(id);
    }

    @Override
    public List<User> getUserByRoleName(String roleName) {
        return getMapper().getUserByRoleName(roleName);
    }

    @Override
    public String getUserRoleNameById(Integer id) {
        return getMapper().getUserRoleNameById(id);
    }

    @Override
    public List<String> getFingerList() {
        return getMapper().getFingerList();
    }

    @Override
    public List<String> getCodeList() {
        return getMapper().getCodeList();
    }

    @Override
    public List<User> queryUsersByTaskId(Map<String, Object> params) {
        return getMapper().queryUsersByTaskId(params);
    }

    @Override
    public User queryByPrimaryKey(Integer id) {
        return getMapper().queryByPrimaryKey(id);
    }

    @Override
    public List<User> getByRouteTaskId(Long routeTaskId) {
        return getMapper().getByRouteTaskId(routeTaskId);
    }

    @Override
    public Integer auth(Map<String, Object> param) {
        return getMapper().auth(param);
    }
}
